package com.atguigu.spzx.manager.controller;

import com.atguigu.spzx.manager.service.SysUserService;
import com.atguigu.spzx.model.dto.system.SysUserDto;
import com.atguigu.spzx.model.entity.system.SysUser;
import com.atguigu.spzx.model.vo.common.Result;
import com.github.pagehelper.PageInfo;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author LT
 * @create 2024-03-12-18:48
 */
@RestController
@Tag(name = "用户管理模块")
@RequestMapping("/admin/system/sysUser")
public class SysUserController {

    @Resource
    SysUserService sysUserService;

    @GetMapping("/findDtoPage/{pageNum}/{pageSize}")
    public Result findDtoPage(@PathVariable("pageNum") Integer pageNum,
                              @PathVariable("pageSize") Integer pageSize,
                               SysUserDto sysUserDto){
        PageInfo<SysUser> page = sysUserService.findDtoPage(pageNum,pageSize,sysUserDto);
        return Result.ok(page);

    }

    @GetMapping("/findSysUserById/{id}")
    public Result findSysUserById(@PathVariable("id") Long id){
        SysUser sysUser = sysUserService.findSysUserById(id);
        return Result.ok(sysUser);
    }

    @GetMapping("/findAll")
    public Result findAll(){
        List<SysUser> list = sysUserService.findAll();
        return Result.ok(list);
    }

    @PostMapping("/saveSysUser")
    public Result saveSysUser(@RequestBody SysUser sysUser){
        sysUserService.saveSysUser(sysUser);
        return Result.ok();
    }

    @PutMapping("/UpdateById")
    public Result UpdateById(@RequestBody SysUser sysUser){
        sysUserService.UpdateById(sysUser);
        return Result.ok();
    }

    @DeleteMapping("/deleteById/{id}")
    public Result deleteById(@PathVariable("id") Long id){
        sysUserService.deleteById(id);
        return Result.ok();
    }


}
